<template>
  <div class="index-page">
    <div class="page-center page-nav">
      <div class="page-center-content">
        <div class="nav-left">
          <span class @click="doinBusiness">进入企业版</span>
        </div>
        <div class="nav-right">
          <router-link to="/communication">沟通</router-link>
          <span>|</span>
          <router-link to="/send">投递记录</router-link>
          <span>|</span>
          <el-dropdown trigger="click" @command="handleCommand">
            <div style="display:flex;align-items:center;">
              <img :src="userInfo.image" alt>
              <span>
                {{userInfo.name ? userInfo.name : userInfo.talentName}}
                <i
                  class="el-icon-caret-bottom"
                  style="color:#fff"
                ></i>
              </span>
            </div>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="1">账号设置</el-dropdown-item>
              <el-dropdown-item command="2">银行账户</el-dropdown-item>
              <el-dropdown-item command="3">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
    </div>
    <div class="page-center page-navs">
      <div class="page-center-content">
        <img src="../assets/img/register/logo.png" class="navs-logo" alt @click="toIndex">
        <el-menu mode="horizontal" class="nvas-menu">
          <el-menu-item v-for="(item, index) in navsList" :key="index">
            <router-link :to="item.to">{{item.label}}</router-link>
          </el-menu-item>
        </el-menu>
      </div>
    </div>
    <div class="page-content">
      <keep-alive :include="/^keep-/">
        <router-view></router-view>
      </keep-alive>
    </div>
  </div>
</template>

<script>
import _subject from '../assets/utils/subject'
export default {
  data() {
    return {
      index: true, //用来控制尾部是否显示
      activeIndex: '0',
      userInfo: {},
      navsList: [
        { label: '首页', to: '/index' },
        { label: '职位', to: '/job' },
        { label: '我的简历', to: '/resume' }
      ],
      imageSub: null
    }
  },
  methods: {
    jumpNav(item, index) {
      this.index = true
      this.activeIndex = index
      this.$router.push({ path: item.to })
    },
    handleCommand(command) {
      //点击下拉菜单
      this.activeIndex = -1
      if (command == 1) {
        //点击账号设置
        this.index = false
        // console.log('账号设置')
        this.$router.push({ path: '/setting/binding' })
      } else if (command == 2) {
        //点击银行账号
        this.index = false
        //console.log('银行账号设置')
        this.$router.push({ path: '/setting/bank' })
      } else {
        //点击退出登录
        _g.apiPost('/login/logout.do', {}).then(res => {
          _g.toMessage(res)
          if (res.status == 0) {
            localStorage.removeItem(localSaved.userInfo)
            localStorage.removeItem(localSaved.jobBannerData)
            localStorage.removeItem(localSaved.footerData)
            this.$router.push({ path: '/login' })
          }
        })
      }
    },
    doLogin() {
      //跳转到登录页面
      this.$router.push({ path: '/login' })
    },
    doRegister() {
      //跳转到注册页面
      this.$router.push({ path: '/register' })
    },
    doinBusiness() {
      //跳转到企业版
      window.location.href = 'http://company.gcs360.com/login'
    },
    getUserInfo() {
      this.userInfo = JSON.parse(localStorage.getItem(localSaved.userInfo))
    },
    toIndex() {
      this.$router.push({ path: '/index' })
    }
  },
  created() {
    let self = this
    this.imageSub = _subject.event.subscribe({
      next(t) {
        console.log('image', t)
        if (t) {
          self.getUserInfo()
          _subject.event.next(null)
        }
      }
    })
  },
  destroyed() {
    if (this.imageSub) {
      this.imageSub.unsubscribe()
    }
  },
  mounted() {
    this.getUserInfo()
  },
  components: {}
}
</script>
